# SMB2 (J) Disassembly Project

## Update 10/04/2007

Added more labels to sm2main_.asm; now the 3 main routines (Start, NMI, and IRQ) are completely labelled, including all their subroutines, excluding OperModeExecutionTree (in NMI) and its (several) subroutines!

## Update 10/01/2007

Here is a description of the command-line arguments to be made in the use of CDLDIS:

Game Filename: Filename of the binary to be disassembled
File Starting Address: What address in the game binary's to start disassembly
CDL Filename: File name of the Code/Date Logger file
CDL Starting Address: What address in the CDL file to start at
No. Bytes: The number of bytes to disassemble
Out Filename: The output text filename
Print Address?: Type 'y' which will cause non-assembleable output that is capitalized and has the memory address printed at the beginning of every line; for another result, type something else, like 'n'.
Org: The memory address that the Game Starting Address gets loaded into. The diassembler assumes that the relativity of a file address to the game starting address will be the same as the relativity of a a memory address; in other words, 5 bytes from the game starting will also be 5 bytes from the memory address/7 bytes/8 bytes/and so on.

To use this on an NES game with bank loading would be clumsier, though not impossible. You would simply have to know that you cannot reset the Org in the middle of the disassembly. You would have to do a separate disassembly for each bank. Of course, the creation of a BAT file for this purpose could be an interesting project for making a program that largely automates it, or I could just update the CDLDIS program.

## Update 09/30/2007

To clarify, unless some small modifications are made, cdldis may be a bit difficult to get to work with an NES game, being designed for the purposes of disassembling SMB2.

OK, I have updated the cdl and dis files for "sm2main_" by causing the memory from 61dd-61e0 to be logged as code.

In addition, I had thus then finished the sound engine in "sm2main_" and the victory music sound engine in "sm2data3". I had also finished the main routine and all subroutines of it. I have also finished the NMI and the IRQ and all their subroutines.

All files have been updated.

Also, I have added the following file, a batch file for running asm6:

make.bat

To get started, at least with assembling the game, first download FDSINFO, and do the command prompt like so:

fdsinfo smb2.fds -o [name of subdirectory if you want] [>redirect output if you want]

This will get you the necessary .bin files: "kyodaku-", "sm2data1", and "sm2data2".

After this, download the source assembly files:

SM2MAIN
SM2DATA2
SM2DATA3
SM2DATA4

followed by the diskmain and defines files.

Then, get ASM6. Following this, you can get make.bat which helps you to set up an assembly. Make sure all files are put in the same directly.

I hope that this can help to get you going, by being to assemble it in the first place! ^_^

Good luck and work hard!

Hello, this is a project for a disassembly of Super Mario Bros. 2 (the Japanese game) for the Famicom Disk System (FDS). I have been working on this project on my own, but alas lately I have a full-time job, am going to school full-time, and am working on listening to and reading as much Japanese as possible during my spare time. This leaves little time left open to other pursuits, such as this unfortunately.

As much as others may say, Do your own work and quit bothering us, I have to respond that as much as I want this done, I think other pursuits are more worth my time at the moment (unfortunately). Nevertheless, it is not that I have not provided anything, as the reader will see below, but it is that I believe I can provide certain tools so that perhaps a person less capable can do this themselves.

(For this please follow this in order, as there is a lot to organize and I'm doing this quickly. Please ask questions by e-mail if you have any confusion. I will answer as soon as possible.)

So, what have I done so far? So far, I have modified FCEUXD SP v1.07 to the point where it can no longer be called that; it is now called FCEU ABS. The full name is:

Family Computer Emulator Ultra (Extended Debugger Sebastian Porst) Alphabet Soup v1.00

Here it is available for download:

FCEU ABS v1.00
(Source Code)

Anyway, among the other features provided (mentioned in the text file therein), there is now a code/data logger that works for the FDS; well, sort of. Except that this goes by RAM, rather than the actual file itself. It nevertheless works for these purposes. Open it up and try it out if you like. The text file describes the format of the CDL files for the FDS.

With this (and with assistance from the source of the SMB2 NES-ization project by loopyNES) I have created CDL files for each of the "files" in the SMB2 disk image (which you're going to have to get for yourself unfortunately), to a high degree of accuracy (possibly a few errors; e-mail me (link provided in image at bottom to prevent spamming) for any errors). Here are the CDL files:

SM2MAIN
SM2DATA2
SM2DATA3
SM2DATA4

I created a special disassembler to create "bare reference" disassemblies of these files in the disk image. Here is the disassembler:

CDLDIS
(Source Code)
(Include file stolen from FCEU ABS ^_^)

Of course, the next question is, How did I locate these files in the disk image? Well, I created a program that can read a disk image (or an image of multiple disks) that is in the standard FDS format and produce information about it; it can also optionally export the files in the disk image to files on your hard drive. Here is the program for download:

FDSINFO
(Source Code)

(With this too, since I won't provide them, you can get the contents of the files "kyodaku-", "sm2char1", and "sm2char2" this way, so you can use them in your assemblies of this game.)

With this, among other things, it tells you how big the file is, its starting address in memory, and which memory it's stored in.

CDLDIS can produce two kinds of disassemblies, one that contains the address values right next to each of the instructions and data bytes/words and is in all caps (to let you know the addresses you are working with) and the other that is meant to be reassembleable in loopy's ASM6, which is going to be the primary assembler used for this project (it's very easy and simple to work with and works perfectly with the kind of assembly required for an FDS disk image). Anyway, here is the one with the address values:

SM2MAIN
SM2DATA2
SM2DATA3
SM2DATA4

(You can get the original BIN files yourself by using FDSINFO on a copy of the disk image.)

Here is what is meant to be reassembled with ASM6:

SM2MAIN
SM2DATA2
SM2DATA3
SM2DATA4

(This has already been partly modified with some labels added to it. This is the "work in progress" that I want help with.)

Finally, here is the main "disk linking file" that you are meant to have ASM6 run on (make sure all the other files are in the same directory) along with the Definitions files as it currently is (thanks to doppelganger for letting me steal his labels). To assemble this, in the same folder you will also need to put "kyodaku-.bin", "sm2char1.bin", and "sm2char2.bin", which will be gotten by running FDSINFO on the disk image and having it export these files. With this, ASM6 will produce an assembly that works perfectly.

To help make the data bytes more concise, or to turn them into data words, I have created two programs (one that produces labels and one that doesn't). Here they are:

QUICKDIS (no labels)
(Source Code)
QUIKDIS2 (labels--which must be specified)
(Source code)

You put the in file (the BIN file you can get with FDSINFO), the out file (which will be a text file), the "org" of the file (what RAM address the first byte of the file is at when it is loaded by the game), the start (i.e. which RAM address (pick RAM address, not file address!) your data will start at), the end (the RAM address of the byte immediately following the last byte you want read--i.e. if you want read up to 69ff, put 6a00), label (the label that gets put on top of this, in the "[label]:" format), dsize (either 1 (for byte) or 2 (for word) and if the difference between end and start is not divisible by dsize, then its modulus will be subtracted from the end address to produce the new end address, and row size (how many data bytes/words will get printed per line before the newline--this is in, as are all other things, hexadecimal).

It can take a lot of time though to this for each data that you want to format, so to speed things up I came out with BATMAKE (Source). This allows you to define a constant outside on the left in the first line and on the right in the second line that you want to use in your BAT file (for quickdis); the subsequent lines define the changing inner part of each repeating instruction (this would be the start and ending bytes).

Now, I did not make much use of BATMAKE, because even that was too slow. You had to put start address, end address, etc. So, instead, I created BATMAKE2 (Source). This allows you to put the label first, hit tab, then put the address starting address. Then in the next line you put the label and the starting address for the next data; the starting address for this one will be used as the end address for the last one. Then you end it by putting a throwaway label (which you need) such as "end" and the end address of the final file. (Remember the end address for this will always be the byte immediately following the last byte to be read!) This will then produce the necessary BAT file to run QUIKDIS2, which will work. Here is an example of the "batter" file for this and here is the BAT file that was produced.

My goal is to have this disassembly have all references to the $6000-$DFFF region be properly labelled with the labels applied to the correct addresses; also to make sure references to the $0000-$07FF and $E000-$FFFF regions are labelled as much as possible. When you make modifications that add labels, please e-mail me the parts that you added labels for, the filename(s) of this, the address range(s) modified (or give it in a way to where I know where to insert the new version with the labels that you made and where to take out the old one).

Every time these modifications are made, they must be done in such a way that the game remains assembleable with ASM6, unchanged in its assembled form from the original disk image (except perhaps the bytes in the disk header that can be classified as "useless"); the labels must also accurately depict the function of the parts of the program concerned and must not simply be named the present file/address of the location (unless the part to be labelled has a function that is unknowable or a useless) function. You may, as much as you want "steal" the labels from doppelganger's SMB1 disassembly (with permission from him), provided they are for use in this only and they still accurately describe the functions being labelled. If these criteria are not met, then the modifications cannot be posted. If they are, then you will receive credit for them, and they will be posted here to the main page with information on what was changed, and who changed it.

Please submit all comments, questions, and modifications to my e-mail address, here as a very poorly image written with my mouse using my right hand, which I do not normally write with (I think it may help with its avoiding being picked up by spammers' "text-in-image detectors"):

Thank you! Just note that I do not condone doing anything which is illegal.